<!DOCTYPE html>
<html>
<head>
    {include file="_Fragment/meta" /}
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" lay-filter="reload">
            <div class="layui-form-item">

                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="key" placeholder="学员名称|工号" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="user-table" lay-filter="user-table"></table>
    </div>
</div>

<script type="text/html" id="user-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="surveyAnalyze">
        <i class="layui-icon layui-icon-chart"></i>
        数据分析
    </button>
</script>

<script type="text/html" id="user-bar">
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
</script>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['table', 'form', 'jquery', 'common'], function() {
        let table = layui.table;
        let form = layui.form;
        let common = layui.common;
        let $ = layui.jquery;
        let resource_id = {$resource_id};
        let classes_id = {$classes_id};
        let survey_id = {$survey_id};

        let cols = [
            [
                {
                    title: 'Carol ID',
                    field: 'userid',
                    align: 'center',
                },
                {
                    title: '姓名',
                    field: 'name',
                    align: 'center',
                },

                {
                    title: 'Division',
                    field: 'division',
                    align: 'center',
                },
                {
                    title: '部门',
                    field: 'department_name',
                    align: 'center',
                },
                {
                    title: '课件名称',
                    field: 'title',
                    align: 'center',
                },
                {
                    title: '开始学习时间',
                    field: 'start_time',
                    align: 'center',
                },
                {
                    title: '学习时长(S)',
                    field: 'learning_time',
                    align: 'center',
                },
                {
                    title: '提交时间',
                    field: 'submit_time',
                    align: 'center',
                },
                {
                    title: '操作',
                    toolbar: '#user-bar',
                    align: 'center',
                    width: 80
                }
            ]
        ]

        table.render({
            elem: '#user-table',
            url: '/Classes/getSurveyLogList?resource_id='+resource_id+'&classes_id='+classes_id,
            page: {layout:['count', 'prev', 'page', 'next', 'skip']},
            limit: 5,
            cols: cols,
            //skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter',{
                title: '导出学习明细' //标题
                ,layEvent: 'export' //事件名，用于 toolbar 事件中使用
                ,icon: 'layui-icon-export' //图标类名
            }]
        });
        form.on('submit(user-query)', function(data) {
            table.reload('user-table', {
                where: data.field
                ,page: {
                    curr: 1, //重新从第 1 页开始
                    layout:['count', 'prev', 'page', 'next', 'skip']
                }
                ,limit: 5,
            })
            return false;
        });



        table.on('tool(user-table)', function(obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            }
        });

        table.on('toolbar(user-table)', function(obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'export') {
                window.export();
            } else if (obj.event === 'surveyAnalyze') {
                window.surveyAnalyze();
            }
        });

        window.surveyAnalyze = function() {
            layer.open({
                type: 2,
                title: '数据分析',
                shade: 0.1,
                area: [common.isModile()?'100%':'900px', common.isModile()?'100%':'600px'],
                content: '/Classes/surveyAnalyze?resource_id='+resource_id+'&classes_id='+classes_id
            });
        }


        window.remove = function(obj) {
            layer.confirm('确定要删除该条数据吗?', {
                icon: 3,
                title: '提示'
            }, function(index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: "/Classes/deleteSurveyLog",
                    data:{id:obj.data.id, survey_id:survey_id, classes_id:classes_id},
                    dataType: 'json',
                    type: 'post',
                    success: function(result) {
                        layer.close(loading);
                        if (result.status == 0) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function() {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 3000
                            });
                        }
                    }
                })
            });
        }


        // 数据导出
        window.export = function() {
            var field = form.val('reload');

            layer.confirm('确定要导出学习明细吗?', {
                icon: 3,
                title: '提示'
            }, function(index) {
                layer.close(index);
                window.open("{:url('exportSurveyLog')}?key="+field.key+'&resource_id='+resource_id+'&classes_id='+classes_id, "_blank");
            });
        };


        window.refresh = function(param) {
            table.reload('user-table');
        }
    })
</script>
</body>
</html>
